package com.wirelesstransfer.AsyncTasks;

import java.util.Map;

import com.wirelesstransfer.activity.status.ConnectionInformation;

import android.os.AsyncTask;
import android.widget.TextView;

public class UpdateStatusStatistics extends AsyncTask<String, String, String> {

	TextView totalUploadSizeValue = AsyncTaskElements.totalUploadSizeValue;
	TextView totalDownloadSizeValue = AsyncTaskElements.totalDownloadSizeValue;
	TextView totalUploadSizeUnit = AsyncTaskElements.totalUploadSizeUnit;
	TextView totalDownloadSizeUnit = AsyncTaskElements.totalDownloadSizeUnit;
	
	ConnectionInformation cInfo = new ConnectionInformation();

	@Override
	protected String doInBackground(String... values) {
//		System.err.println("Executing status statistics.");
		// values contains parameters to execute.		
		
		// Check every 5 (?) seconds if something has happened to the up- and downloads.
		for(int i = 0; i < 100; i++) {
			try {
				Thread.sleep(2000);
				publishProgress("");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
		}

		return null;
	}

	protected void onProgressUpdate(String... values){
	//	System.err.println("Updating status statistics.");
		// values contains parameters from publishProgress.
		
		Map<String, String> up = cInfo.getUploadedSize();
		Map<String, String> down = cInfo.getDownloadSize();

		totalUploadSizeValue.setText(up.get("fileSize"));
		totalDownloadSizeValue.setText(down.get("fileSize"));
		totalUploadSizeUnit.setText(up.get("unit"));
		totalDownloadSizeUnit.setText(down.get("unit"));

	}

}